<?php

/* ========================================================================= */
/* This file is part of the HypnoPHP Framework Library                       */
/* Copyright (c) 2009-2010, Radu Buzea                                       */
/* ========================================================================= */

/**
* @author Radu Buzea
* @copyright Copyright (c) 2009-2010, Radu Buzea (www.hypnosis.ro)
* @license GNU Lesser General Public License (www.gnu.org/copyleft/lesser.html)
* @package HypnoPHP
* @category Core
* @version 1.0.3
*/

defined('HYPNOPHP_APPLICATION') or
die("Cannot use <i>" . basename(__FILE__) . "</i> outside HypnoPHP Application");

// ============================================================================
// Abstract class: BaseModel
// ============================================================================

abstract class HBaseModel extends HBaseObject
{

	protected $__database_object = null;
	protected $__parent_controller = null;

	# ###########################################################################

	/**
	* initialize object properties
	*
	* @return void
	*/
	public function __initialize()
	{
		$this->__database_object = null;
		$this->__parent_controller = null;
		$num_args = func_num_args();
		if ($num_args > 0) {
			$args = func_get_arg(0);
			if (is_array($args) && isset($args[0]) && is_object($args[0])) {
				$this->__parent_controller = $args[0];
			}
		}
		$main_app_database_object = HApplication::getDatabase();
		if (!is_null($main_app_database_object)) {
			$this->__database_object = $main_app_database_object;
		}
	}

	# ###########################################################################

	/**
	* Database object property getter method
	*
	* @return object (HBaseDb) or null
	*/
	function __get_database()
	{
		return $this->__database_object;
	}

	# ###########################################################################

	/**
	* Database object property setter method
	*
	* @param object $param HBaseDb
	* @return void
	*/
	function __set_database($database_object = null)
	{
		if (!empty($database_object) && is_object($database_object)) {
			$this->__database_object = $database_object;
		}
	}

	# ###########################################################################

}
